home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / TinyGL / ami / content / ad709 / tinygl / src / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-15  |  3.5 KB  |  167 lines

  1. /*$T misc.c GC 1.137 08/09/02 17:47:18 */
  2.  
  3. /*$6
  4.  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  5.  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  6.  */
  7.  
  8. #include "zgl.h"
  9. #include "msghandling.h"
  10.  
  11. /* */
  12.  
  13. void glopViewport(GLContext *c, GLParam *p) {
  14.     int xsize, ysize, xmin, ymin, xsize_req, ysize_req;
  15.     /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  16.  
  17.     xmin = p[1].i;
  18.     ymin = p[2].i;
  19.     xsize = p[3].i;
  20.     ysize = p[4].i;
  21.  
  22.     /* we may need to resize the zbuffer */
  23.     if(c->viewport.xmin != xmin || c->viewport.ymin != ymin || c->viewport.xsize != xsize ||
  24.            c->viewport.ysize != ysize) {
  25.         xsize_req = xmin + xsize;
  26.         ysize_req = ymin + ysize;
  27.  
  28.         if(c->gl_resize_viewport && c->gl_resize_viewport(c, &xsize_req, &ysize_req) != 0) {
  29.             gl_fatal_error("glViewport: error while resizing display");
  30.         }
  31.  
  32.         xsize = xsize_req - xmin;
  33.         ysize = ysize_req - ymin;
  34.         if(xsize <= 0 || ysize <= 0) {
  35.             gl_fatal_error("glViewport: size too small");
  36.         }
  37.  
  38.         tgl_trace("glViewport: %d %d %d %d\n", xmin, ymin, xsize, ysize);
  39.         c->viewport.xmin = xmin;
  40.         c->viewport.ymin = ymin;
  41.         c->viewport.xsize = xsize;
  42.         c->viewport.ysize = ysize;
  43.  
  44.         c->viewport.updated = 1;
  45.     }
  46. }
  47.  
  48. /* */
  49. void glopEnableDisable(GLContext *c, GLParam *p) {
  50.     int code = p[1].i;
  51.     int v = p[2].i;
  52.  
  53.     switch(code) {
  54.     case GL_BLEND:
  55.         c->blending_enabled = v;
  56.         break;
  57.     case GL_CULL_FACE:
  58.         c->cull_face_enabled = v;
  59.         break;
  60.     case GL_LIGHTING:
  61.         c->lighting_enabled = v;
  62.         break;
  63.     case GL_COLOR_MATERIAL:
  64.         c->color_material_enabled = v;
  65.         break;
  66.     case GL_TEXTURE_2D:
  67.         c->texture_2d_enabled = v;
  68.         break;
  69.     case GL_NORMALIZE:
  70.         c->normalize_enabled = v;
  71.         break;
  72.     case GL_DEPTH_TEST:
  73.         c->depth_test = v;
  74.         break;
  75.     case GL_POLYGON_OFFSET_FILL:
  76.         if(v) {
  77.             c->offset_states |= TGL_OFFSET_FILL;
  78.         }
  79.         else {
  80.             c->offset_states &= ~TGL_OFFSET_FILL;
  81.         }
  82.         break;
  83.     case GL_POLYGON_OFFSET_POINT:
  84.         if(v) {
  85.             c->offset_states |= TGL_OFFSET_POINT;
  86.         }
  87.         else {
  88.             c->offset_states &= ~TGL_OFFSET_POINT;
  89.         }
  90.         break;
  91.     case GL_POLYGON_OFFSET_LINE:
  92.         if(v) {
  93.             c->offset_states |= TGL_OFFSET_LINE;
  94.         }
  95.         else {
  96.             c->offset_states &= ~TGL_OFFSET_LINE;
  97.         }
  98.         break;
  99.     default:
  100.         if(code >= GL_LIGHT0 && code < GL_LIGHT0 + MAX_LIGHTS) {
  101.             gl_enable_disable_light(c, code - GL_LIGHT0, v);
  102.         }
  103.         else {
  104.             /* fprintf(stderr,"glEnableDisable: 0x%X not supported.\n",code); */
  105.         }
  106.         break;
  107.     }
  108. }
  109.  
  110. /* */
  111. void glopShadeModel(GLContext *c, GLParam *p) {
  112.     int code = p[1].i;
  113.     c->current_shade_model = code;
  114. }
  115.  
  116. /* */
  117. void glopCullFace(GLContext *c, GLParam *p) {
  118.     int code = p[1].i;
  119.     c->current_cull_face = code;
  120. }
  121.  
  122. /* */
  123. void glopFrontFace(GLContext *c, GLParam *p) {
  124.     int code = p[1].i;
  125.     c->current_front_face = code;
  126. }
  127.  
  128. /* */
  129. void glopPolygonMode(GLContext *c, GLParam *p) {
  130.     int face = p[1].i;
  131.     int mode = p[2].i;
  132.  
  133.     switch(face) {
  134.     case GL_BACK:            c->polygon_mode_back = mode; break;
  135.     case GL_FRONT:            c->polygon_mode_front = mode; break;
  136.     case GL_FRONT_AND_BACK: c->polygon_mode_front = mode; c->polygon_mode_back = mode; break;
  137.     default:                assert(0);
  138.     }
  139. }
  140.  
  141. /* */
  142. void glopBlendFunc(GLContext *c, GLParam *p) {
  143.     int sfactor = p[1].i;
  144.     int dfactor = p[2].i;
  145.  
  146.     if(sfactor != GL_SRC_ALPHA || dfactor != GL_ONE_MINUS_SRC_ALPHA) {
  147.         gl_fatal_error("Invalid blending functions combination\n");
  148.     }
  149. }
  150.  
  151. /* */
  152. void glopHint(GLContext *c, GLParam *p)
  153. {
  154. #if 0
  155.     int target = p[1].i;
  156.     int mode = p[2].i;
  157.  
  158.     /* do nothing */
  159. #endif
  160. }
  161.  
  162. /* */
  163. void glopPolygonOffset(GLContext *c, GLParam *p) {
  164.     c->offset_factor = p[1].f;
  165.     c->offset_units = p[2].f;
  166. }
  167.